<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!--  //现有字符串如下 name1与value1为一组参数信息 name1表示为参数名value1表示为值  
        var search = '?name1=value1&name2=value2';
        // 封装一个函数可以获取到指定参数的值 -->
    <script>
        var search = '?name1=value1&name2=value2&name3=value3&name4=value4';
        function fn(key, str) {
            var res =search.replace("?", "").split("&");
            var arr=[];
            for(var s=0;s < res.length;s++){
                arr[s]=res[s].split("=")
            }
            var obj = {};
            for (var i = 0; i < arr.length; i++) {
                for (var j = 1; j < arr[i].length; j++) {
                    obj[arr[i][j - 1]] = arr[i][j]
                }
            }
            return obj[key]
        }
        console.log(fn("name4",search));

            // var res=searchobj.fliter(function(item,key){
            //     return item>"?"
            // })
    </script>
</body>

</html>